﻿namespace Armon.Lib.Collections
{
    public static class EnumerableExtension
    {
        public static bool IsNullOrEmpty<T>(this IEnumerable<T> values)
        {
            return values is null || !values.Any();
        }

        public static bool AnyNullOrWhiteSpace(this IEnumerable<string> values)
        {
            return values.Any(string.IsNullOrWhiteSpace);
        }

        public static bool AllNullOrWhiteSpace(this IEnumerable<string> values)
        {
            return values.All(string.IsNullOrWhiteSpace);
        }

        public static IEnumerable<TSource> Do<TSource>(this IEnumerable<TSource> source, Action<TSource> selector)
        {
            var list = source.ToList();
            foreach (var item in list)
            {
                selector(item);
            }
            return list;
        }

        public static IEnumerable<TSource> Do<TSource>(this IEnumerable<TSource> source, Action<TSource, int> selector)
        {
            var list = source.ToList();
            for (var i = 0; i < list.Count; i++)
            {
                selector(list[i], i);
            }
            return list;
        }
    }
}